#include "TestWrapper.h"

// implementation code of WrapperFactory - do NOT modify the next 5 lines
AbstractWrapper* WrapperFactory::wrapper = 0;
AbstractWrapper* WrapperFactory::createWrapper() {
  if (wrapper == 0) wrapper = new TestWrapper;
  return wrapper;
}
// Do not modify the following line
volatile bool TestWrapper::GlobalStop = false;

// a default constructor
TestWrapper::TestWrapper() {
	followsTable = Follows();
	parentTable = Parent();
	ast = AST();
	procTable = ProcTable();
	varTable = VarTable();
	callsTable = Calls();
	modifiesTable = Modifies();
	usesTable = Uses();
	// create any objects here as instance variables of this class
	// as well as any initialization required for your spa program
}

// method for parsing the SIMPLE source
void TestWrapper::parse(std::string filename) {
	const char* name = filename.c_str();
	Parser parser = Parser(name, ast, procTable, varTable, followsTable, parentTable);
	try{
		parser.buildPKB();
	} catch (CustomException e){
		return;
	}
	DesignExtractor designExtractor = DesignExtractor(ast);
	designExtractor.createModifiesTable(modifiesTable);
	designExtractor.createUsesTable(usesTable);
	deTable = AST::getDesignEntityTable();

}

// method to evaluating a query
void TestWrapper::evaluate(std::string query, std::list<std::string>& results){
	try {
		QueryPreprocessor qp = QueryPreprocessor(query);
		CompleteQuery *qc = qp.buildQuery();

		QueryEvaluator qe = QueryEvaluator(ast, deTable, followsTable, 
			modifiesTable, parentTable, usesTable, varTable);
		results = qe.evaluateCompleteQuery(qc);
	} catch (CustomException e) {
		return;
	}
}
